<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="goto()">跳转</button>
    <script>
        // bom:浏览器对象模型
        console.log(window);
        // location对象 链接上的url信息
        console.log(window.location);
        // href：url信息  http://www.baidu.com/m/index.html?id=1
        console.log(location.href);
        //主机地址
        console.log(location.host);
        console.log(location.hostname,'不带端口号');
        console.log(location.port,'端口号');
        console.log(location.pathname,'路径');
        console.log(location.protocol,'协议');
        // 获取地址栏上的参数
        // 获取地址
        let url = location.href
    //     console.log(url);
    //    let params = url.split('?')[1].split('&')
    //    console.log(params);
    //    params.forEach(item=>{
    //     console.log(item.split('='));
    //     document.write(item.split('=')[1])
        
    //    })
        // 传入url的参数 id=123&text=666
        console.log(url.split('?')[1]);
        
        let params = new URLSearchParams(url.split('?')[1])
         console.log(params);
        //  获取URL参数
        console.log(params.get('id'),'id');
        console.log(params.get('text'),'text');
        // 设置参数
        params.set('id','999')
        console.log(params.get('id'),'id');
        // 删除参数
        params.delete('text')
        console.log(params.get('text'),'text');


        function goto(params) {
            location.href = 'http://127.0.0.1:5500/bom/bom2.html?id=123&text=456'
            
        }
        
        
        
    </script>
</body>
</html>